import random

from selenium.common import NoSuchElementException

from 水质.utils.Logger import logger
from 水质.utils.click import wait_clickId, wait_Id, find_child_elements, clickText


def test_station_choose(driver):
    parent = wait_Id(driver, "rv_param")
    els = find_child_elements(parent)
    if len(els) > 0:
        random_element = random.choice(els)
        try:
            random_element.click()
            logger.log("点击元素成功")
        except NoSuchElementException:
            logger.log("元素未找到或无法点击")
    wait_clickId(driver, "btn_confirm")





def test_map_filter(driver):
    wait_clickId(driver, "ll_custom_selection")
    test_station_choose(driver)
    wait_clickId(driver, "ll_custom_selection")
    clickText(driver, "运维状态")
    test_station_choose(driver)
    wait_clickId(driver, "ll_custom_selection")
    clickText(driver, "地标类型")
    test_station_choose(driver)
